package com.hamizhong.iflowers.web.action.admin.orders;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import com.hamizhong.iflowers.service.ICityService;
import com.hamizhong.iflowers.service.IGoodsService;
import com.hamizhong.iflowers.service.IOrdersService;
import com.hamizhong.iflowers.service.IProvinceService;
import com.hamizhong.iflowers.utils.MyConstants;
import com.hamizhong.iflowers.utils.MyErrorMsgConstants;
import com.hamizhong.iflowers.web.base.MyBaseAjaxAction;
import com.hamizhong.iflowers.web.dto.IOPResultDto;
import com.hamizhong.iflowers.web.vo.AdminVO;
import com.hamizhong.iflowers.web.vo.IObjectVO;

public class AjaxUpdateOrderStateAction extends MyBaseAjaxAction {
	private IOrdersService iOrdersService = null;
	private IProvinceService iProvinceService = null;
	private ICityService iCityService = null;
	private IGoodsService iGoodsService = null;
	public IOrdersService getiOrdersService() {
		return iOrdersService;
	}
	public void setiOrdersService(IOrdersService iOrdersService) {
		this.iOrdersService = iOrdersService;
	}
	public IProvinceService getiProvinceService() {
		return iProvinceService;
	}
	public void setiProvinceService(IProvinceService iProvinceService) {
		this.iProvinceService = iProvinceService;
	}
	public ICityService getiCityService() {
		return iCityService;
	}
	public void setiCityService(ICityService iCityService) {
		this.iCityService = iCityService;
	}
	public IGoodsService getiGoodsService() {
		return iGoodsService;
	}
	public void setiGoodsService(IGoodsService iGoodsService) {
		this.iGoodsService = iGoodsService;
	}
	@Override
	protected JSONObject doRequest() {
		logger.info("...invoke...AjaxUpdateOrderStateAction...");
		String orderId = getRQ().getParameter("orderId");
		String newState = getRQ().getParameter("newState");
		JSONObject jo = new JSONObject();
		JSONArray ja = new JSONArray();
		JSONObject jobj = null;
		AdminVO adminVO = (AdminVO) getSSN().getAttribute(MyConstants.IFLOWERS_LOGIN_ADMIN_VO);
		if(adminVO == null) {
			jo.put("msg", MyErrorMsgConstants.ERR_LOGIN);
			jo.put("result", MyConstants.AJAX_FAILED_LOGIN);
			return jo;
		}
		IOPResultDto<IObjectVO> dto = iOrdersService.updateOrderState(Integer.valueOf(orderId), Integer.valueOf(newState));
		if(dto.isSuccess()) {
			jo.put("result", MyConstants.AJAX_SUCCESS);
		}else {
			jo.put("result", MyConstants.AJAX_FAILED_ALERT);
			jo.put("msg", dto.getErrorMSG());
		}
		return jo;
	}

}
